<?php
/**
 * 攀枝花市智慧人社就医服务中间件
 *
 *
 * @author jack
 */

namespace Pzhrs\Controller;

class PzhMedicalControlController
{
    // SoapClient 对象
    private $soap = FALSE;

    // 记录是否为正式环境
    private $isFormal = FALSE;

    //是否开启缓存
    private static $CACHE = false;

    // 医疗机构科室列表缓存建
    private static $CACHE_INSTITUTION_CLASS_LIST = 'CACHE_INSTITUTION_CLASS_LIST';


    static $URL_API = 'http://220.166.60.252:8083/wxjk.dll/wsdl/Iwxjk';//http://192.168.203.55:8078/HisService.asmx?WSDL
    static $back_URL_API = "http://localhost:8081/";

    //医院id
    private $hospitalId;

    //自助机id
    private $userId;

    /**
     * 构造函数
     */
    function __construct()
    {
        header('Content-Type: text/html; charset=utf-8');
        $this->hospitalId = 75;
        if (!method_exists($this, ACTION_NAME)) {
            $function = ACTION_NAME;
            A('Receive')->$function();
        }
    }

    public function xml_to_array($list){
        $ob= simplexml_load_string($list);
        $json  = json_encode($ob);
        $configData = json_decode($json, true);
        return $configData;
    }

    public $hospitalKey = array(
        "75" => "7daf7603429012aeae417fa9beed9c75",
    );
    /**
     * 请求His API
     *
     *   使用SoapClient请求HIS webservice接口
     *
     * @param String $Flag 类型
     * @param String $Content xml请求内容
     * @param String $Result_K 返回xml中的跟节点key
     *
     * @return array
     */


    private function soapGetDate($Flag, $Content)
    {
//        $this->isFormal = ($_SERVER['SERVER_NAME']!="localhost" && "histest.mobimedical.cn"!=$_SERVER['SERVER_NAME']);
        $this->isFormal = false;

        if (!$this->soap) {
            $this->soap = new \SoapClient(self::$URL_API, array("connection_timeout" => 15));
        }
        try {

            /* 正式环境 */
            if ($this->isFormal) {
                //专线接口,走平台
                try {
                    $result = $this->soap->Weixin($Content);
                } catch (\Exception $e) {
                    $fileContent = $Content . "\n" . $e->getMessage();
                    $dir = "soapGetDate/";
                    \Org\Util\File::createDir($dir);
                    file_put_contents($dir . $Flag . "_error.txt", $fileContent);
                    return array('ResultCode' => -1, "ErrorMsg" => "系统异常，请稍后重试21！");
                }
                $Result_K = "Weixin" . Result;

                /* 测试环境 */
            } else {
                $result = $this->soap->$Flag( $Content);
                /* 记录请求日志   */
                $fileContent = $Content . "\r" . var_export($result, true);
                $dir = "soapGetDate/" . date("Y-m-d") . "/" . $Flag . "/";
                $filename = date("H_i_s") . "_" . rand(10000, 99999);
                writeLog($dir, $filename, $fileContent);

                return json_decode(json_encode(json_decode(json_encode((array)simplexml_load_string(substr($result, 54)), true))), true);
            }


        } catch (\Exception $e) {
            /* 记录请求异常日志  */
            $fileContent = $Content . "\n" . $e->getMessage();
            $dir = "soapGetDate/" . date("Y-m-d") . "/" . $Flag . "/";
            $filename = date("H_i_s") . "_error";
            writeLog($dir, $filename, $fileContent);
            return array('ResultCode' => -1, "ErrorMsg" => "系统异常，请稍后重试22！");
            exit;
        }
    }


    function Post($url, $method, $post = null)
    {
        if (is_array($post)) {
            ksort($post);
            $content = http_build_query($post);
            $content_length = strlen($content);
            $options = array(
                'http' => array(
                    'method' => 'POST',
                    'header' =>
                        "Content-type: application/x-www-form-urlencoded; charset=utf-8\r\n" .
                        "Content-length: $content_length\r\n",
                    'content' => $content
                )
            );
            $res = file_get_contents($url, false, stream_context_create($options));
            $fileContent = var_export($post, true) . "\r" . var_export($res, true) . "\r" . var_export(json_decode($res, true), true);
            $dir = "soapGetDateXt/" . date("Y-m-d") . "/" . $method . "/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
            return $res;
        }
    }

    /**
     * 中间件签名验证
     * @param array $params
     * @return string
     */
    function middelEnCodeSign($params)
    {
        ksort($params);
        $preString = "";
        $time = $params['time'];
        $hospitalId = $params['hospitalId'];
        foreach ($params as $k => $v) {
            if ($k == 'time' || $k == 'sign' || !$v)
                continue;
            $preString .= $k . "=" . $v;
        }

        $keyString = $this->hospitalKey[$hospitalId];
        //加密
        return sha1($preString . $keyString . $time);
    }

    public function Test_jj()
    {
        //echo '122';die();
        //$client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');
        $url='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $s=new \SoapClient($url);
        /*
         *SoapHeader参数说明如下所示:
         *'http://tempuri.org/'   namespace(命名空间可省略)
         *'MySoapHeader'          SoapHeader头的类名
         *'array(...)'            存放标识身份的字符串参数
         *'true'                  是否必须处理该header
        */
        $mmkj='http://yinhai.com';
        $code='yinhai@789'; //授权码
        $funNo='WX_001';    //交易编号 
        $xml_xx="<input><aac001>4000612523</aac001><startrow>1</startrow><endrow>3</endrow><inputxml><inputxml><aac002>510402198306076317</aac002><aac003>张帆</aac003></inputxml></inputxml></input>";
        $apiUrl='http://pzh.91cure.com/index.php?g=Home&m=Test&a=pzh_sign';
        $params1 = array();
        $params1['content']=$xml_xx;
        $xmlsing=$this->PostData_jm($apiUrl,$params1);

        $auth_header = array( "jybh" =>$funNo ,"systemKey" =>$code ,"source" =>$xml_xx,"signature" =>$xmlsing  );
        $authvalues = new \SoapVar($auth_header, SOAP_ENC_OBJECT,"system",$mmkj);  
        $u = new \SoapHeader($mmkj, 'system', $authvalues);
        $s->__setSoapHeaders($u);
        $params['inputxml']=$xml_xx;
        $suc=$s->callBusiness($params);
        $data=$suc->return;
        $tesres = $this->xml_to_array($data);
        dump($tesres);
    }
    //养老保险查询
    function EndowmentInsurance_Query(){
        $identyId='510402198306076317';   //身份证号码
        $name='张帆';       //姓名
        $funNo='WX_001';    //交易编号
        $xml="<input><aac001>4000612523</aac001><startrow>1</startrow><endrow>3</endrow><inputxml><inputxml><aac002>".$identyId."</aac002><aac003>".$name."</aac003></inputxml></inputxml></input>";
        $url='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $client=new \SoapClient($url);
        dump($xml);
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        $datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['message'];
            $returnArr['data']['name']=$name;                   //姓名
            $returnArr['data']['identyId']=$identyId;           //身份证号码
            $returnArr['data']['insured_units']=$datares['aab004'];     //参保所在单位名称
            $returnArr['data']['insured_status']=$datares['aac008'];    //参保状态
            $returnArr['data']['payment_status']=$datares['aac031'];    //缴费状态
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //最大缴费期号
            $returnArr['data']['payment_total_local']=$datares['aic027'];   //在本地缴费总金额
            $returnArr['data']['payment_total_monthly']=$datares['aic079']; //累计缴费总月数
            $returnArr['data']['payment_total_money']=$datares['aic040'];   //截至当前个人账户累计存储额         
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['message'];
        };
        dump($returnArr);
    }

    /**
     * 统一调接口方法 
     * $xml       接口传递的参数
     * $funNo     接口的方法名
     * $client    接口需要调用的webservice对象 
     * */
    function Get_service_api($xml,$funNo,$client){
        $mmkj='http://yinhai.com';
        $code='wx20170921'; //授权码
        //$apiUrl='http://pzh.91cure.com/index.php?g=Home&m=Test&a=pzh_sign';
        //$apiUrl='http://127.0.0.1:442/index.php?g=Whszxyy&m=WhszxyyControlxin1&a=pzh_sign';
        //$params1 = array();
        //$params1['content']=$xml;
        //$xmlsing=$this->PostData_jm($apiUrl,$params1);

        $content = htmlspecialchars_decode($xml);
        $priKey = file_get_contents($rsaPrivateKeyPem);  
        //echo $content;
        $priKey='-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQCQq3qatgsHLl4E2OKsMDYS07yp+Vdxxq6oHgdp5DmzXlt28b/u
/ezex7kNrNHWVcycaLqeX43Xp4ByO6ELjVbfP2XNhXN7pOMh5KNLbUvGP5YultKl
AMRk25HN9rjp8RHZHlS0qpR5Y5sitK3AR19VlAPKUaoslBlCaAPqGwsQkwIDAQAB
AoGARzt30eeixHVrK73S1m+ioGCLO7IfAVGPvA2VHumWE6B5LrbYB4gV8peqoXYf
mAaFCdpzUPnBsJa0IwsDP9nnFJ6EwYfvFtgihipWgx3HZ0tyLu6gNW9ORFP9RCtE
u05J8JbjYOcJP3Pwu3RQ715yoxbmAe2SzwHiXrJSUgVSsQkCQQD+YpPlkxLrGbxI
nbNAZQRO4udJIUmBt0uTNiJ8TEZ9h45aeLRYgtBy28YMBgCkBJACFuJ7MufPvwQC
4lPHJKT/AkEAkZaYCIs1A778bDvxIyGhTcUmNxTti2HEFbUFfkXXDKaxu53uxNCw
roztQD3rtGEhSGQKoO8ax0bjyIDzaX8wbQJAGsJn6Gh2PwDwC3t7VbTKpTm9NrYn
s1uCubOiIQ0tBRtzYBT+c6kfIFX6GV2wR5CrTWz22hraw8HGPD9urK4wJQJAA+V9
6CyhnJoN82+fQotx37z5CtxahzJ0pwgTP4/q84G6nATcERRsxh8rcl614jv/Qgq7
ZhdAJjk1e3ZIDXjD+QJAIF07entOK7DhmHKOXJPtgMaVdXd1QUER1NuDpQTBKTim
hjs4JBVWvXgUwPH1lZaiSoJnHrL/G3Sw3K/DJEEdKw==
-----END RSA PRIVATE KEY-----';
        $res = openssl_pkey_get_private($priKey);
        openssl_sign($content, $sign, $res);
        openssl_free_key($res);  
        //$sign = base64_encode($sign);  
        $xmlsing = bin2hex($sign);

        $auth_header = array( "jybh" =>$funNo ,"systemKey" =>$code ,"source" =>$xml,"signature" =>$xmlsing  );
        $authvalues = new \SoapVar($auth_header, SOAP_ENC_OBJECT,"system",$mmkj);  
        $u = new \SoapHeader($mmkj, 'system', $authvalues);
        $client->__setSoapHeaders($u);
        $params['inputxml']=$xml;
        $suc=$client->callBusiness($params);
        $data=$suc->return;

        /*$dir = "soapGetDate/" . date("Y-m-d") . "/".$funNo."_xml/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $data);*/

        $tesres = $this->xml_to_array($data);
		if (isset($tesres['code']) && $tesres['code'] == 'NOERROR') {
            $tesres['code'] = "1";
        }
        return  $tesres;
    }
    /**
     * 数字签名
     * $url         签名地址
     * $post        签名参数
     * */
    function PostData_jm($url, $post = null) {
        //dump($url);
        if (is_array($post)) {
            ksort($post);
            $content = http_build_query($post);
            $content_length = strlen($content);
            $options = array(
                'http' => array(
                    'method' => 'POST',
                    'header' =>
                    "Content-type: application/x-www-form-urlencoded\r\n"."Content-length: $content_length\r\n",
                    'content' => $content
                )
            );
            $now = time();
            //print_r($options);
            $context = stream_context_create($options);
             //echo $context;
            $res = file_get_contents($url, false, $context);
            //echo '-11111-';
            //echo $res;//die();
            //return substr(urlencode($res),9);//
            return $res;
        }
    }

    /**
     * 医院信息
     * @param 
     */
    function GetHospitalInformation(){
        $funNo='HIS015';    //交易编号
        $xml="<input><startrow>1</startrow><endrow>100</endrow></input>";
        //dump(C('URL_API'));die();
        $client=new \SoapClient(C('URL_API'));
        //$client='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        //dump($result_list);
        //echo $result_list;die();
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS015_re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
            //echo $result_list;die;
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
        $te_arry=$result_list['output']['resultset']['row']['akb020'];
        $ywsz_jj=$result_list['output']['resultset']['row'];
        if(is_array($result_list['message']))
        {
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        }; 
        if($result_list['code']=='1')
        {
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;   
            if($te_arry)
            {
                $returnArr['data'][0]['hospitalCode']=$ywsz_jj['akb020'];   //医院代码
                $returnArr['data'][0]['hospitalName']=$ywsz_jj['akb021'];   //医院名称
                $returnArr['data'][0]['hospitalAddress']=$ywsz_jj['aae006'];    //医院地址
                $returnArr['data'][0]['hospitalPhone']=$ywsz_jj['aae005'];      //联系电话
                $returnArr['data'][0]['hospitalGrade']=$ywsz_jj['aka101'];     //医院等级
                //$returnArr['data'][0]['hospitalDescription']=$ywsz_jj['aae013'];     //医院描述
                if(is_array($ywsz_jj['aae013']))
                {
                    $returnArr['data'][0]['hospitalDescription']='';  //医院描述
                }else
                {
                    $returnArr['data'][0]['hospitalDescription']=$ywsz_jj['aae013']; 
                };
            } else { 
                foreach ($ywsz_jj as $k => $v) {
                    $returnArr['data'][$k]['hospitalCode']=$ywsz_jj[$k]['akb020'];   //医院代码
                    $returnArr['data'][$k]['hospitalName']=$ywsz_jj[$k]['akb021'];   //医院名称
                    $returnArr['data'][$k]['hospitalAddress']=$ywsz_jj[$k]['aae006'];    //医院地址
                    $returnArr['data'][$k]['hospitalPhone']=$ywsz_jj[$k]['aae005'];      //联系电话
                    $returnArr['data'][$k]['hospitalGrade']=$ywsz_jj[$k]['aka101'];     //医院等级
                    //$returnArr['data'][0]['hospitalDescription']=$ywsz_jj[$k]['aae013'];     //医院描述
                    if(is_array($ywsz_jj[$k]['aae013']))
                    {
                        $returnArr['data'][$k]['hospitalDescription']='';  //医院描述
                    }else
                    {
                        $returnArr['data'][$k]['hospitalDescription']=$ywsz_jj[$k]['aae013']; 
                    };
                }
            }
        }else
        {//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        //dump($returnArr);
        /* 记录请求日志   */
            $fileContent = var_export($returnArr, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS015_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        echo json_encode($returnArr);
    }

    /**
     * 科室信息
     * @param 
     */
    function GetDepartment(){
        //$hospitalCode='525009'; //医院编码
        //$deptCode='';       //科室编号
        
        $hospitalCode  = $_POST['hospitalcode'];    //医院编码
        $deptCode  = $_POST['deptcode'];    //科室编号

        if($deptcode=='0')
        {
            $deptcode='';
        };
        /* 记录请求日志   */
            $fileContent = json_encode($_POST);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS001_re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        $funNo='HIS001';    //交易编号
        $xml="<input><Request><deptcode>".$deptcode."</deptcode><functionid>".$funNo."</functionid><akb020>".$hospitalCode."</akb020></Request></input>";
        //dump(C('URL_API'));//die();

        $client=new \SoapClient(C('URL_API'));
        //$client='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = $xml.'+'.json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS001_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();

        //echo $result_list;die();
        $te_arry=$result_list['item']['deptCode'];
        $ywsz_jj=$result_list['item'];
        if(is_array($result_list['resultMessage']))
        {
            $llmessage='';  
        }else{
            $llmessage=$result_list['resultMessage']; 
        }; 
        if($result_list['resultCode']=='0')
        {
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;   
            if($te_arry)
            {
                $returnArr['data'][0]['hospitalCode']=$hospitalCode;    //医院代码
                $returnArr['data'][0]['deptCode']=$ywsz_jj['deptCode'];     //科室代码
                $returnArr['data'][0]['deptName']=$ywsz_jj['deptName'];     //科室名称
                $returnArr['data'][0]['hasChild']=$ywsz_jj['hasChild'];     //是否有子科室 0：无子科室1：有子科室
                $returnArr['data'][0]['parentDeptCode']=$ywsz_jj['parentDeptCode'];//父科室代码 0：无父科室
                //$returnArr['data'][0]['deptDescription']=$ywsz_jj['deptDescription'];   //科室介绍
                //$returnArr['data'][0]['deptLocation']=$ywsz_jj['deptLocation'];   //科室位置描述

                if(is_array($ywsz_jj['deptDescription']))
                {
                    $returnArr['data'][0]['deptDescription']='';  //科室介绍
                }else
                {
                    $returnArr['data'][0]['deptDescription']=$ywsz_jj['deptDescription']; 
                };

                if($ywsz_jj['deptLocation']=='null')
                {
                    $returnArr['data'][0]['deptLocation']='';  //科室位置描述
                }else
                {
                    $returnArr['data'][0]['deptLocation']=$ywsz_jj['deptLocation']; 
                };
            } else { 
                foreach ($ywsz_jj as $k => $v) {
                    $returnArr['data'][$k]['hospitalCode']=$hospitalCode;    //医院代码
                    $returnArr['data'][$k]['deptCode']=$ywsz_jj[$k]['deptCode'];     //科室代码
                    $returnArr['data'][$k]['deptName']=$ywsz_jj[$k]['deptName'];     //科室名称
                    $returnArr['data'][$k]['hasChild']=$ywsz_jj[$k]['hasChild'];     //是否有子科室 0：无子科室1：有子科室
                    $returnArr['data'][$k]['parentDeptCode']=$ywsz_jj[$k]['parentDeptCode'];//父科室代码 0：无父科室
                    if(is_array($ywsz_jj[$k]['deptDescription']))
                    {
                        $returnArr['data'][$k]['deptDescription']='';  //科室介绍
                    }else
                    {
                        $returnArr['data'][$k]['deptDescription']=$ywsz_jj[$k]['deptDescription']; //科室位置描述
                    };

                    if($ywsz_jj[$k]['deptLocation']=='null')
                    {
                        $returnArr['data'][$k]['deptLocation']='';  //科室位置描述
                    }else
                    {
                        $returnArr['data'][$k]['deptLocation']=$ywsz_jj[$k]['deptLocation']; //科室位置描述
                    };
                }
            }
        }else
        {//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        //dump($returnArr);
        /* 记录请求日志   */
            $fileContent = json_encode($returnArr);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS001_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        echo json_encode($returnArr);
    }
	
	 function GetDepartmentTest(){
        $hospitalCode='525009'; //医院编码
        $deptCode='';       //科室编号
        
        //$hospitalCode  = $_POST['hospitalcode'];    //医院编码
        //$deptCode  = $_POST['deptcode'];    //科室编号

        if($deptcode=='0')
        {
            $deptcode='';
        };
        /* 记录请求日志   */
            $fileContent = json_encode($_POST);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetDept_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        $funNo='HIS001';    //交易编号
        $xml="<input><Request><deptcode>".$deptcode."</deptcode><functionid>".$funNo."</functionid><akb020>".$hospitalCode."</akb020></Request></input>";
        //dump(C('URL_API'));//die();

        $client=new \SoapClient(C('URL_API'));
        //$client='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetDept_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list, JSON_UNESCAPED_UNICODE);die();
	 }

    /**
     * 医生信息
     * @param 
     */
    function GetDoctor(){
        /*$hospitalcode='525009'; //医院编码
        $deptcode='2011401';       //科室编号
        $doctorcode='0';       //医生编号*/

        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $deptcode  = $_POST['deptcode'];    //科室编号
        $doctorcode  = $_POST['doctorcode'];    //科室编号
        if($deptcode=='0')
        {
            $deptcode='';
        };
        if($doctorcode=='0')
        {
            $doctorcode='';
        };

        $funNo='HIS002';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><deptcode>".$deptcode."</deptcode><doctorcode>".$doctorcode."</doctorcode><functionid>".$funNo."</functionid><akb020>".$hospitalcode."</akb020></Request></input>";

		/* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS002_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        
        /*$xml_re="<Response>
            <resultcode>0</resultcode>
            <resultmessage></resultmessage>
            <item>
                <deptcode>2011401</deptcode>
                <deptname>门诊眼科</deptname>
                <doctorcode>12345</doctorcode>
                <doctorname>谢医生</doctorname>
                <doctorskill>医生擅长</doctorskill>
                <doctorintrodution>医生简介</doctorintrodution>
                <doctortitle>医生职称</doctortitle>
            </item>
            </Response>";*/
        
        //echo $xml_re;die();
        $client=new \SoapClient(C('URL_API'));
        //$client='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS002_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //dump($result_list);//die();
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
        $te_arry=$result_list['item']['deptCode'];
        $ywsz_jj=$result_list['item'];
        if(is_array($result_list['resultMessage']))
        {
            $llmessage='';  
        }else{
            $llmessage=$result_list['resultMessage']; 
        }; 
        if($result_list['resultCode']=='0')
        {
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;   
            if($te_arry)
            {
                $returnArr['data'][0]['deptCode']=$ywsz_jj['deptCode'];     //科室代码
                $returnArr['data'][0]['deptName']=$ywsz_jj['deptName'];     //科室名称
                $returnArr['data'][0]['hasChild']=$ywsz_jj['hasChild'];     //是否有子科室 0：无子科室1：有子科室
                $returnArr['data'][0]['parentDeptCode']=$ywsz_jj['parentDeptCode'];//父科室代码 0：无父科室
                $returnArr['data'][0]['deptDescription']=$ywsz_jj['deptDescription'];   //科室介绍
                $returnArr['data'][0]['deptLocation']=$ywsz_jj['deptLocation'];   //科室位置描述

                if(is_array($ywsz_jj['deptDescription']))
                {
                    $returnArr['data'][0]['deptDescription']='';  
                }else
                {
                    $returnArr['data'][0]['deptDescription']=$ywsz_jj['deptDescription']; 
                };

                if($ywsz_jj['deptLocation']=='null')
                {
                    $returnArr['data'][0]['deptLocation']='';  
                }else
                {
                    $returnArr['data'][0]['deptLocation']=$ywsz_jj['deptLocation']; 
                };
            } else { 
                foreach ($ywsz_jj as $k => $v) {
                    $returnArr['data'][$k]['deptCode']=$ywsz_jj[$k]['deptCode'];     //科室代码
                    $returnArr['data'][$k]['deptName']=$ywsz_jj[$k]['deptName'];     //科室名称
                    $returnArr['data'][$k]['hasChild']=$ywsz_jj[$k]['hasChild'];     //是否有子科室 0：无子科室1：有子科室
                    $returnArr['data'][$k]['parentDeptCode']=$ywsz_jj[$k]['parentDeptCode'];//父科室代码 0：无父科室
                    $returnArr['data'][$k]['deptDescription']=$ywsz_jj[$k]['deptDescription'];   //科室介绍
                    $returnArr['data'][$k]['deptLocation']=$ywsz_jj[$k]['deptLocation'];   //科室位置描述

                    if(is_array($ywsz_jj[$k]['deptDescription']))
                    {
                        $returnArr['data'][$k]['deptDescription']='';  
                    }else
                    {
                        $returnArr['data'][$k]['deptDescription']=$ywsz_jj[$k]['deptDescription']; 
                    };

                    if($ywsz_jj[$k]['deptLocation']=='null')
                    {
                        $returnArr['data'][$k]['deptLocation']='';  
                    }else
                    {
                        $returnArr['data'][$k]['deptLocation']=$ywsz_jj[$k]['deptLocation']; 
                    };
                }
            }
        }else
        {//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        dump($returnArr);
        /* 记录请求日志   */
            $fileContent = var_export($returnArr, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetDept_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        echo json_encode($returnArr);
    }

    /**
     * 号源信息查询
     * @param 
     */
    function GetSchedule(){
        /*$hospitalcode='525009'; //医院编码
        $deptcode='2011601';       //科室编号
        $doctorcode='00004';       //医生编号
        $startdate='2017-12-01';   //开始时间
        $enddate='2017-12-11';      //结束时间*/

        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $deptcode  = $_POST['deptcode'];        //科室编号
        $doctorcode  = $_POST['doctorcode'];    //医生编号
        $startdate  = date('Y-m-d', strtotime($_POST['startdate']));      //开始时间
		$enddate  = date('Y-m-d', strtotime($_POST['enddate']));      //结束时间
        if($doctorcode=='0')
        {
            $doctorcode='';
        };

        $funNo='HIS003';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><deptcode>".$deptcode."</deptcode><doctorcode>".$doctorcode."</doctorcode><startdate>".$startdate."</startdate><enddate>".$enddate."</enddate><functionid>".$funNo."</functionid><akb020>".$hospitalcode."</akb020></Request></input>";

		/* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS003_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS003_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
        //dump($result_list);die();
    }
    
    /**
     * 挂号锁号
     * @param 
     */
    function GetRegisteredlock(){

        /*$hospitalcode='525009'; //医院编码
        $userid='tc_123';         //第三方ID
        $code ='gh|-407|11';   //医院挂号序号
        $psordnum ='TC2017120502';   //平台订单号 TC2017120501  TC20171205
        $deptcode='2011601';      //科室代码
        $doctorcode='00004';    //医生代码
        $scheduledate='2017-12-06';      //号源日期
        $timeflag='1';      //时段 1：上午 2：下午3：晚上
        $begintime='09:00';     //分时开始时间
        $endtime='10:00';       //分时结束时间
        $regfee='19.00';        //挂号费
        $pattype='1';       //患者类型 1成年，2儿童
        $patname='张小波';       //患者姓名
        $patsex='m';        //性别 m：男，f：女
        $patage='28';        //年龄
        $patbirth='1989-12-28';      //出生年月
        $patidtype='1';     //患者证件类型 身份证 1 居住证 2 签证   3 护照   4 户口本 5 军人证 6 港澳通行证 7 其他   8
        $patidno='429006198912281230';       //患者证件号码
        $patmobile='13670076316';     //手机号码
        $pataddress='';    //地址
        $guardname='';     //监护人姓名
        $guardidtype='';   //监护人证件类型
        $guardidno='';     //监护人证件号*/
        $tcylkey = C('TCYL_KEY');

        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $tcylkey.$_POST['userid'];    //第三方ID
        $code  = $_POST['code'];        //医院挂号序号
        $psordnum  = $_POST['psordnum'];        //医院订单号
        $deptcode  = $_POST['deptcode'];    //科室代码
        $doctorcode  = $_POST['doctorcode'];      //医生代码
        $scheduledate  = $_POST['scheduledate'];      //号源日期
        $timeflag  = $_POST['timeflag'];      //时段 1：上午 2：下午3：晚上
        $begintime  = $_POST['begintime'];      //分时开始时间
        $endtime  = $_POST['endtime'];      //分时结束时间
        $regfee  = $_POST['regfee'];      //挂号费
        $pattype  = $_POST['pattype'];      //患者类型 1成年，2儿童
        $patname  = $_POST['patname'];      //患者姓名
        $patsex  = $_POST['patsex'];      //性别 m：男，f：女

        $patage  = $_POST['patage'];      //年龄
        $patbirth  = $_POST['patbirth'];      //出生年月
        $patidtype  = isset($_POST['patidtype']) ? $_POST['patidtype'] : '';      //患者证件类型
        $patidno  = isset($_POST['patidno']) ? $_POST['patidno'] : '';      //患者证件号码
        $patmobile  = $_POST['patmobile'];      //手机号码
		$patmobile = '00000000000';//不给真实手机号到医院
        $pataddress  = $_POST['pataddress'];      //地址
        $guardname  = $_POST['guardname'];      //监护人姓名
        $guardidtype  = $_POST['guardidtype'];      //监护人证件类型
        $guardidno  = $_POST['guardidno'];      //监护人证件号
		//如果为儿童，监护人的身份证号也要传，医院没有儿童挂号
		if($pattype==2 && $guardidno!='' && $patidno==''){
			$patidno = $guardidno;
		}

        $funNo='HIS004';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><code>".$code."</code><psordnum>".$psordnum."</psordnum><deptcode>".$deptcode."</deptcode><doctorcode>".$doctorcode."</doctorcode><scheduledate>".$scheduledate."</scheduledate><timeflag>".$timeflag."</timeflag><begintime>".$begintime."</begintime><endtime>".$endtime."</endtime><regfee>".$regfee."</regfee><pattype>".$pattype."</pattype><patname>".$patname."</patname><patsex>".$patsex."</patsex><patage>".$patage."</patage><patbirth>".$patbirth."</patbirth><patidtype>".$patidtype."</patidtype><patidno>".$patidno."</patidno><patmobile>".$patmobile."</patmobile><pataddress>".$pataddress."</pataddress><guardname>".$guardname."</guardname><guardidtype>".$guardidtype."</guardidtype><guardidno>".$guardidno."</guardidno><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS004_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        //dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS004_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
    }

    /**
     * 号源取消锁定
     * @param 
     */
    function GetScheduleUnlock(){
        /*$hospitalcode='525009'; //医院编码
        $userid='tc_123';         //第三方ID
        $hisordnum='gh|-407|10';   //医院订单号
        $psordnum='TC2017120501';      //平台订单号
        $cancelreason=''; //取消原因*/
        $tcylkey = C('TCYL_KEY');

        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $tcylkey.$_POST['userid'];        //第三方ID
        $hisordnum  = $_POST['hisordnum'];  //医院订单号
        $psordnum  = $_POST['psordnum'];    //平台订单号
        $cancelreason  = $_POST['cancelreason'];      //取消原因

        $funNo='HIS005';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><hisordnum>".$hisordnum."</hisordnum><psordnum>".$psordnum."</psordnum><cancelreason>".$cancelreason."</cancelreason><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS005_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        //dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS005_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();		
    }
    

    /**
     * 挂号记录查询
     * @param 
     */
    function GetRegisteredRecords(){
        /*$hospitalcode='525009'; //医院编码
        $userid='tc_123';         //第三方ID
        $patname='张小波';   //患者姓名
        $patidno='429006198912281230';      //患者身份证*/
        $tcylkey = C('TCYL_KEY');

        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $tcylkey.$_POST['userid'];        //第三方ID
        $patname  = $_POST['patname'];      //患者姓名
        $patidno  = $_POST['patidno'];      //患者身份证

        $funNo='HIS006';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><patname>".$patname."</patname><patidno>".$patidno."</patidno><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS006_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        //dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS006_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
        
    }

    /**
     * 费用支付通知
     * @param 
     */
    function GetFeePaynot(){
        /*$hospitalcode='525009'; //医院编码
        $userid='tc_123';         //第三方ID
        $hisordnum='gh|-407|14|1';   //医院订单号
        $psordnum='TC2017120602';      //平台订单号
        $medicarenum='';   //医保就诊序号 当为社保卡时此项不能为空
        $costtype='1';      //费用类型 1挂号费2门诊费
        $paymode='1';       //支付方式 1：微信支付 2：支付宝 3:社保卡
        $payamt='19.00';        //总费用
        $coordinationpay='';      //医保统筹支付
        $scardamt='';      //医保个人账户支付
        $cashpay='19.00';       //现金支付金额
        $cardaccount='';  //账户余额  医保支付时返回支付后余额
        $isaddpay='2';      //是否有门诊调增费用 1是,2否
        $agtordnum='wx2017120602';   //收单机构流水号 对应收单机构（如微信、支付宝）用于标识一笔支付交易的流水号
        $paytime='2017-12-06 15:23:23';  //支付时间 格式：yyyy-mm-dd 24hh:mi:ss */
        $tcylkey = C('TCYL_KEY');

        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $tcylkey.$_POST['userid'];        //第三方ID
        $hisordnum  = $_POST['hisordnum'];  //医院订单号
        $psordnum  = $_POST['psordnum'];    //平台订单号
        $medicarenum  = $_POST['medicarenum'];      //医保就诊序号 当为社保卡时此项不能为空
        $costtype  = $_POST['costtype'];    //费用类型 1挂号费2门诊费
        $paymode  = $_POST['paymode'];      //支付方式 1：微信支付 2：支付宝 3:社保卡
        $payamt  = $_POST['payamt'];        //总费用
        $coordinationpay  = $_POST['coordinationpay'];  //医保统筹支付
        $scardamt  = $_POST['scardamt'];    //医保个人账户支付
        $cashpay  = $_POST['cashpay'];      //现金支付金额
        $cardaccount   = $_POST['cardaccount']; //账户余额  医保支付时返回支付后余额
        $isaddpay  = $_POST['isaddpay'];    //是否有门诊调增费用 1是,2否
        $agtordnum  = $_POST['agtordnum'];  //收单机构流水号
        $paytime  = $_POST['paytime'];      //支付时间
        $noticetype  = $_POST['notice_type'];      //费用支付通知 1支付通知2退费通知

        $funNo='HIS008';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><hisordnum>".$hisordnum."</hisordnum><psordnum>".$psordnum."</psordnum><akc190>".$medicarenum."</akc190><costtype>".$costtype."</costtype><paymode>".$paymode."</paymode><payamt>".$payamt."</payamt><coordinationpay>".$coordinationpay."</coordinationpay><scardamt>".$scardamt."</scardamt><cashpay>".$cashpay."</cashpay><cardaccount>".$cardaccount ."</cardaccount><isaddpay>".$isaddpay."</isaddpay><agtordnum>".$agtordnum."</agtordnum><paytime>".$paytime."</paytime><noticetype>".$noticetype."</noticetype><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";

        /* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS008_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        //dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS008_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
    }

    /**
     * 门诊缴费记录查询(包含 待缴费,已缴费，作废)
     * @param 
     */
    function GetPaymentRecords(){
        /*$hospitalcode='525009'; //医院编码
        $userid='tc_123';             //第三方ID
        $patidno='429006198912281230';     //身份证号
        $patname='张小波';       //姓名
        $payflag='1'; */      //单据状态 1表示待缴费 2表示已缴费3作废  
        $tcylkey = C('TCYL_KEY');

        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $tcylkey.$_POST['userid'];        //第三方ID
		$userid = 'tcyl_ohNH9sqKwgorvsSC9g1aVHiSTrHY';
        $patidno  = $_POST['patidno'];      //身份证号
        $patname  = $_POST['patname'];      //姓名
        $payflag  = $_POST['payflag'];      //单据状态 1表示待缴费 2表示已缴费3作废 

        $funNo='HIS009';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><patidno>".$patidno."</patidno><patname>".$patname."</patname><payflag>".$payflag."</payflag><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS009_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        /*$xml_re="<Response>
            <resultCode>1</resultCode>
            <resultMessage>成功</resultMessage>
            <item>
                <hisOrdNum>000051283800|2</hisOrdNum>
                <payName>大换药[含材料]</payName>
                <deptName>门诊中医科</deptName>
                <doctorName>谈钊</doctorName>
                <totalAmt>28.00</totalAmt>
                <coordinationpay>0</coordinationpay>
                <scardAmt>0</scardAmt>
                <Cashpay>0</Cashpay>
                <payFlag>1</payFlag>
            </item>
            </Response>";
        $response = simplexml_load_string($xml_re ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();*/

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        //dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS009_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
    }

    /**
     * 门诊缴费记录明细查询
     * @param 
     */
    function GetPaymentRecordsDetails(){
        /*$hospitalcode='525009'; //医院编码
        $userid='tc_123';             //第三方ID
        $hisordnum='000051283800|9';     //医院订单号 */ 

        $tcylkey = C('TCYL_KEY');

        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $tcylkey.$_POST['userid'];        //第三方ID
        $hisordnum  = $_POST['hisordnum'];      //医院订单号

        $funNo='HIS010';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><hisordnum>".$hisordnum."</hisordnum><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS010_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        //dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS010_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
    }

    /**
     * 订单取消或者是退费
     * @param 
     */
    function GetOrderRefund(){
        /*$hospitalcode='525009'; //医院编码
        $userid='tc_123';             //第三方ID
        $hisordnum='gh|-407|14|1';   //医院订单号
        $psordnum='TC2017120602';    //平台订单号
        $medicarenum='';     //医保就诊序号
        $paymode='1';     //支付方式 1：微信支付   2：支付宝   3:社保卡
        $payamt='19.00';      //总费用
        $agtordnum='wx2017120602';   //收单机构流水号 */ 
        $tcylkey = C('TCYL_KEY');

        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $tcylkey.$_POST['userid'];        //第三方ID
        $hisordnum  = $_POST['hisordnum'];      //医院订单号
        $psordnum  = $_POST['psordnum'];      //平台订单号
        $medicarenum  = $_POST['medicarenum'];      //医保就诊序号
        $paymode  = $_POST['paymode'];      //支付方式 1：微信支付   2：支付宝   3:社保卡
        $payamt  = $_POST['payamt'];      //总费用
        $agtordnum  = $_POST['agtordnum'];      //收单机构流水号
        $type  = $_POST['type'];      //1挂号2门诊

        $funNo='HIS011';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><hisordnum>".$hisordnum."</hisordnum><psordnum>".$psordnum."</psordnum><akc190>".$medicarenum."</akc190><paymode>".$paymode."</paymode><payamt>".$payamt."</payamt><agtordnum>".$agtordnum."</agtordnum><type>".$type."</type><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS011_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        //dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS011_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
    }

    /**
     * 检验报告列表查询
     * @param 
     */
    function GetInspectionReport(){
        /*$hospitalcode='525009'; //医院编码
        $userid='tc_123';             //第三方ID
        $patidno='320106198310290811';     //身份证号
        $patname='周杰';       //姓名
        $begindate='2017-04-01';   //开始日期
        $enddate='2017-12-11';   */
        $tcylkey = C('TCYL_KEY');

        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $tcylkey.$_POST['userid'];        //第三方ID
        $patidno  = $_POST['patidno'];      //身份证号
        $patname  = $_POST['patname'];      //姓名
        $begindate  = $_POST['begindate'];  //开始日期
        $enddate  = date('Y-m-d', strtotime($_POST['enddate'])+86400);      //结束日期

        $funNo='HIS012';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><patidno>".$patidno."</patidno><patname>".$patname."</patname><begindate>".$begindate."</begindate><enddate>".$enddate."</enddate><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS012_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        /*$xml_re="<Response>
            <resultcode>1</resultcode>
            <resultmessage></resultmessage>
            <item>
                <inspectid>检验id1</inspectid>
                <inspectname>检验名称1</inspectname>
                <inspecttime>2017-12-02 15:49:00</inspecttime>
                <inspectstatus>报告状态</inspectstatus>
                <reporttime>2017-12-02 15:49:00</reporttime>
                <examtime>2017-12-02 15:49:00</examtime>
                <deptcode>12345</deptcode>
                <deptname>内科</deptname>
                <doctorcode>1111</doctorcode>
                <doctorname>赵医生</doctorname>
                <exedeptcode>12345</exedeptcode>
                <exedeptname>内科</exedeptname>
                <reporter>张三</reporter>
                <auditor>李四</auditor>
            </item>
            <item>
                <inspectid>检验id2</inspectid>
                <inspectname>检验名称2</inspectname>
                <inspecttime>2017-12-02 15:49:00</inspecttime>
                <inspectstatus>报告状态</inspectstatus>
                <reporttime>2017-12-02 15:49:00</reporttime>
                <examtime>2017-12-02 15:49:00</examtime>
                <deptcode>12345</deptcode>
                <deptname>内科</deptname>
                <doctorcode>1111</doctorcode>
                <doctorname>赵医生</doctorname>
                <exedeptcode>12345</exedeptcode>
                <exedeptname>内科</exedeptname>
                <reporter>张三</reporter>
                <auditor>李四</auditor>
            </item>
        </Response>";

        $response = simplexml_load_string($xml_re ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();*/

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS012_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //dump($result_list);//die();
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
    }

    /**
     * 检验报告详情查询
     * @param 
     */
    function GetInspectionDetails(){
        /*$hospitalcode='525009'; //医院编码
        $userid='tc_123';             //第三方ID
        $patidno='429006198912281230';     //身份证号
        $patname='张小波';     //姓名
        $inspectid='1712101055';   //检验id  */
        $tcylkey = C('TCYL_KEY');
        
        $hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $tcylkey.$_POST['userid'];        //第三方ID
        $patidno  = $_POST['patidno'];      //身份证号
        $patname  = $_POST['patname'];      //姓名
        $inspectid  = $_POST['inspectid'];  //检验id

        $funNo='HIS013';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><patidno>".$patidno."</patidno><patname>".$patname."</patname><inspectid>".$inspectid."</inspectid><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = $xml;
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS013_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        /*$xml_re="<Response>
            <resultcode>1</resultcode>
            <resultmessage></resultmessage>
            <inspectid>检验id1</inspectid>
            <inspectname>检验名称1</inspectname>
            <deptname>内科</deptname>
            <doctorname>赵医生</doctorname>
            <inspecttime>2017-12-02 15:49:00</inspecttime>
            <reporttime>2017-12-02 15:49:00</reporttime>
            <item>
                <itemname>项目名称1</itemname>
                <result>结果1</result>
                <refrange>参考范围</refrange>
                <abnormal>0</abnormal>
            </item>
            <item>
                <itemname>项目名称2</itemname>
                <result>结果2</result>
                <refrange>参考范围</refrange>
                <abnormal>0</abnormal>
            </item>
        </Response>";*/

        /*$response = simplexml_load_string($xml_re ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();*/

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = json_encode($result_list);
            $dir = "soapGetDate/" . date("Y-m-d") . "/HIS013_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        //dump($result_list);//die();
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        //$response = json_encode($response);
        //echo $response;die();
		echo json_encode($result_list);die();
    }


    /********************php验证身份证号码是否正确函数*********************/
    function is_idcard($id) 
    { 
        $id = strtoupper($id); 
        $regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/"; 
        $arr_split = array(); 
        if(!preg_match($regx, $id)) 
        { 
            return FALSE; 
        } 
        if(15==strlen($id)) //检查15位 
        { 
            $regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";      
            @preg_match($regx, $id, $arr_split); 
            //检查生日日期是否正确 
            $dtm_birth = "19".$arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4]; 
            if(!strtotime($dtm_birth)) 
            { 
                return FALSE; 
            } else { 
                return TRUE; 
            } 
        } 
        else      //检查18位 
        { 
            $regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/"; 
            @preg_match($regx, $id, $arr_split); 
            $dtm_birth = $arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4]; 
            if(!strtotime($dtm_birth)) //检查生日日期是否正确 
            { 
                return FALSE; 
            } 
            else
            { 
                //检验18位身份证的校验码是否正确。 
                //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。 
                $arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); 
                $arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); 
                $sign = 0; 
                for($i = 0; $i < 17; $i++ ) 
                { 
                    $b = (int) $id{$i}; 
                    $w = $arr_int[$i]; 
                    $sign += $b * $w; 
                } 
                $n = $sign % 11; 
                $val_num = $arr_ch[$n]; 
                if($val_num != substr($id,17, 1)) 
                { 
                    return FALSE; 
                } //phpfensi.com 
                else
                { 
                    return TRUE; 
                } 
            } 
        } 
      
    } 

	/**
     * 获取/验证手机号码
     * @param
     */
    function phoneVerify(){
        $user_id = C('TCYL_KEY').$_POST['user_id'];//第三方id
        $social_card_no = $_POST['social_card_no'];//社保卡号
        $telphone = $_POST['phone'];//手机号(为空获取手机号,不为空校验手机号)
        $funNo = 'HIS023';    //交易编号
        $appid = $_POST['app_id'];
        $xml = '<input><inputxml><inputxml>
   <user>
<user_id>'.$user_id.'</user_id>
<social_card_no>'.$social_card_no.'</social_card_no>
<telphone>'.$telphone.'</telphone>
<appid>'.$appid.'</appid>
</user></inputxml></inputxml></input>';
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);

        $fileContent = '入参'.$xml.'+出参'.json_encode($result_list);
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS023/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);

        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($result_list);
        //dump($response);
        echo $response;die();
    }

    /**
     * 平台支付密码检测
     * @param 
     */
    function passwordCheck(){
        $user_id = C('TCYL_KEY').$_POST['user_id'];//第三方id
        $social_card_no = $_POST['social_card_no'];//社保卡号
		//$user_id = C('TCYL_KEY').'ohNH9sqKwgorvsSC9g1aVHiSTrHY';
        //$social_card_no = '1000359370';
        $contype = 2;//2验证密码
        $appid = $_POST['app_id'];
        $funNo = 'HIS022';    //交易编号
        $xml = '<input><inputxml><inputxml>
   <user>
<user_id>'.$user_id.'</user_id>
<social_card_no>'.$social_card_no.'</social_card_no>
<contype>'.$contype.'</contype>
<appid>'.$appid.'</appid>
</user></inputxml></inputxml>
</input >';
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);

        $fileContent = '入参'.$xml.'+出参'.json_encode($result_list);
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS022/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);

        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($result_list);
        //dump($response);
        echo $response;die();
    }

    /**
     * 平台支付密码验证
     * @param 
     */
    function passwordVerification(){
        $date['code'] = 1;
        /*$date['state'] = 0;
        $date['message'] = '验证失败';*/
        $date['state'] = 1;
        $date['message'] = '验证成功';
        echo json_encode($date);
    }

    /**
     * 平台支付密码设置
     * @param 
     */
    function passwordSetting(){
        $user_id = C('TCYL_KEY').$_POST['user_id'];//第三方id
        $social_card_no = $_POST['social_card_no'];//社保卡号
		//$user_id = C('TCYL_KEY').'ohNH9sqKwgorvsSC9g1aVHiSTrHY';
        //$social_card_no = '1000359370';
        $user_pwd = $_POST['password'];//密码
        $contype = 1;//1设置密码
        $appid = $_POST['app_id'];
        $funNo = 'HIS022';    //交易编号
        $xml = '<input><inputxml><inputxml>
   <user>
<user_id>'.$user_id.'</user_id>
<social_card_no>'.$social_card_no.'</social_card_no>
<user_pwd>'.$user_pwd.'</user_pwd>
<contype>'.$contype.'</contype>
<appid>'.$appid.'</appid>
</user></inputxml></inputxml>
</input>';
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);

        $fileContent = '入参'.$xml.'+出参'.json_encode($result_list);
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS022/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);
        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($result_list);
        //dump($response);
        echo $response;die();
    }

    /**
     * 平台支付密码重置
     * @param 
     */
    function passwordReset(){
        $date['code'] = 1;
        $date['state'] = 1;
        $date['message'] = '重置成功';
        echo json_encode($date);
    }

    /**
     * 预结算
     * @param 
     */
    function payinsuranceUnifiedorder(){
        $hospital_org_id = $_POST['hospital_org_id'];//医院编号
        $channel_id = $_POST['channel_id'];//渠道号
        $pay_type = $_POST['pay_type'];//结算类型,1为挂号2为门诊
        $user_id = C('TCYL_KEY').$_POST['user_id'];//第三方id
        $social_card_no = $_POST['social_card_no'];//社保卡号
        $user_card_no = $_POST['user_card_no'];//身份证
        $user_name = $_POST['user_name'];//姓名
        $ssp_order_id = $_POST['ssp_order_no'];//平台订单号
        $order_no = $_POST['hospital_order_no'];//第三方订单号
        $total_amount = $_POST['total_amount'];//总交易金额
		$org_pay_amount = $_POST['org_amount'];//医疗统筹支付金额
        $grzhpay_amount = $_POST['self_insurance_amount'];//个人账户支付金额
        $appid = $_POST['app_id'];

        $funNo = 'HIS016';    //交易编号
        //入参
        $xml = '<input><inputxml><inputxml>'.
            '<hospital_org_id>'.$hospital_org_id.'</hospital_org_id>'.
            '<channel_id>'.$channel_id.'</channel_id>'.
            '<pay_type>'.$pay_type.'</pay_type>'.
            '<appid>'.$appid.'</appid>'.
            '<user>'.
                '<user_id>'.$user_id.'</user_id>'.
                '<social_card_no>'.$social_card_no.'</social_card_no>'.
                '<user_card_no>'.$user_card_no.'</user_card_no>'.
                '<user_name>'.$user_name.'</user_name>'.
            '</user>'.
            '<order>'.
                '<ssp_order_id>'.$ssp_order_id.'</ssp_order_id>'.
                '<order_no>'.$order_no.'</order_no>'.
                '<total_amount>'.$total_amount.'</total_amount>'.
				'<org_pay_amount>'.$org_pay_amount.'</org_pay_amount>'.
                '<grzhpay_amount>'.$grzhpay_amount.'</grzhpay_amount>'.
            '</order></inputxml></inputxml>'.
        '</input>';
		$fileContent = '入参'.$xml;
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS016/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);

        $fileContent = '入参'.$xml.'+出参'.json_encode($result_list);
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS016s/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);

        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($result_list);
        //dump($response);
        echo $response;die();
    }

    /**
     * 结算
     * @param 
     */
    function payinsuranceSettlement(){
        $hospital_org_id = $_POST['hospital_org_id'];//医院编号
        $channel_id = $_POST['channel_id'];//渠道号
        $user_id = C('TCYL_KEY').$_POST['user_id'];//第三方id
        $social_card_no = $_POST['social_card_no'];//社保卡号
        $user_card_no = $_POST['user_card_no'];//身份证
        $user_name = $_POST['user_name'];//姓名
        $user_pwd = $_POST['password'];//密码
        $ssp_order_id = $_POST['ssp_order_no'];//平台订单号
        $pay_time = $_POST['pay_time'];//结算时间(年月日时分秒)
        $order_no = $_POST['hospital_order_no'];//第三方订单号
        $total_amount = $_POST['total_amount'];//总交易金额
        $insurance_amount = $_POST['insurance_amount'];//医保支付金额
        $selfpay_amount = $_POST['selfpay_amount'];//现金支付金额
        $youhui_amount = $_POST['coupon_amount'];//youhui金额
		$org_pay_amount = $_POST['org_amount'];//医疗统筹支付金额
        $grzhpay_amount = $_POST['self_insurance_amount'];//个人账户支付金额
        $appid = $_POST['app_id'];
        $funNo = 'HIS017';    //交易编号
        //入参
        $xml = '<input><inputxml><inputxml>'.
            '<hospital_org_id>'.$hospital_org_id.'</hospital_org_id>'.
            '<channel_id>'.$channel_id.'</channel_id>'.
            '<appid>'.$appid.'</appid>'.
            '<user>'.
                '<user_id>'.$user_id.'</user_id>'.
                '<social_card_no>'.$social_card_no.'</social_card_no>'.
                '<user_card_no>'.$user_card_no.'</user_card_no>'.
                '<user_name>'.$user_name.'</user_name>'.
                '<user_pwd >'.$user_pwd.'</user_pwd>'.
            '</user>'.
            '<order>'.
                '<ssp_order_id>'.$ssp_order_id.'</ssp_order_id>'.
                '<pay_time>'.$pay_time.'</pay_time>'.
                '<order_no>'.$order_no.'</order_no>'.
                '<total_amount>'.$total_amount.'</total_amount>'.
                '<insurance_amount>'.$insurance_amount.'</insurance_amount>'.
                '<selfpay_amount>'.$selfpay_amount.'</selfpay_amount>'.
                '<youhui_amount>'.$youhui_amount.'</youhui_amount>'.
				'<org_pay_amount>'.$org_pay_amount.'</org_pay_amount>'.
                '<grzhpay_amount>'.$grzhpay_amount.'</grzhpay_amount>'.
            '</order></inputxml></inputxml>'.
        '</input>';
		$fileContent = '入参'.$xml;
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS017/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);

        $fileContent = '入参'.$xml.'+出参'.json_encode($result_list);
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS017s/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);

        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($result_list);
        //dump($response);
        echo $response;die();
    }

    /**
     * 订单查询
     * @param 
     */
    function payinsuranceQueryorder(){
        $user_id = C('TCYL_KEY').$_POST['user_id'];//第三方id
        $ssp_order_id = $_POST['ssp_order_no'];//平台id
        $funNo = 'HIS018';    //交易编号
        //入参
        $xml = '<input><startrow>1</startrow><endrow>1</endrow><inputxml><inputxml>'.
            '<user_id>'.$user_id.'</user_id>'.
            '<appid>'.$appid.'</appid>'.
            '</inputxml></inputxml>'.'<ssp_order_id>'.$ssp_order_id.'</ssp_order_id>'.
        '</input>';

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);

        $fileContent = '入参'.$xml.'+出参'.json_encode($result_list);
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS018/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);

        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($result_list);
        //dump($response);
        echo $response;die();
    }

    /**
     * 退款
     * @param 
     */
    function payinsuranceRefund(){
        $channel_id = $_POST['channel_id'];//渠道号
        $user_id = C('TCYL_KEY').$_POST['user_id'];//第三方id
        $social_card_no = $_POST['social_card_no'];//社保卡号
        $user_card_no = $_POST['user_card_no'];//身份证
        $user_name = $_POST['user_name'];//姓名
        $ssp_order_id = $_POST['ssp_order_no'];//平台订单号
        $order_no = $_POST['hospital_order_no'];//第三方订单号
        $treatment_record_id = $_POST['treatment_record_id'];//医保就诊序号
        $total_amount = $_POST['total_amount'];//总交易金额
        $insurance_amount = $_POST['insurance_amount'];//医保⽀支付⾦金金额(包括医保个帐)
        $selfpay_amount = $_POST['selfpay_amount'];//现金支付金额
        $cancel_datetime = date('Y-m-d H:i:s', time());//订单取消日期
        $appid = $_POST['app_id'];
        $funNo = 'HIS019';//交易编号
        //入参
        $xml = '<input><inputxml><inputxml>'.
        '<channel_id>'.$channel_id.'</channel_id>'.
        '<appid>'.$appid.'</appid>'.
        '<user>'.
            '<user_id>'.$user_id.'</user_id>'.
            '<social_card_no>'.$social_card_no.'</social_card_no>'.
            '<user_card_no>'.$user_card_no.'</user_card_no>'.
            '<user_name>'.$user_name.'</user_name>'.
        '</user>'.
        '<order>'.
            '<ssp_order_id>'.$ssp_order_id.'</ssp_order_id>'.
            '<order_no>'.$order_no.'</order_no>'.
            '<treatment_record_id>'.$treatment_record_id.'</treatment_record_id>'.
            '<total_amount>'.$total_amount.'</total_amount>'.
            '<insurance_amount>'.$insurance_amount.'</insurance_amount>'.
            '<selfpay_amount>'.$selfpay_amount.'</selfpay_amount>'.
            '<cancel_datetime>'.$cancel_datetime.'</cancel_datetime>'.
        '</order></inputxml></inputxml></input>';
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);

        $fileContent = '入参'.$xml.'+出参'.json_encode($result_list);
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS019/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);

        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($result_list);
        //dump($response);
        echo $response;die();
    }

    /**
     * 下载对帐单(接口无)
     * @param 
     */
    function payinsuranceGetbalancebill(){
        $hospital_org_id = $_POST['hospital_org_id'];//医院编号
        $start_date = $_POST['start_date'];//开始时间
        $end_date = $_POST['end_date'];//结束时间
        $startrow = $_POST['start_row'];//开始页数
        $endrow = $_POST['end_row'];//结束页数
        $funNo = 'HIS024';//交易编号
        //入参
        $xml = '<input><startrow>'.$startrow.'</startrow><endrow>'.$endrow.'</endrow><inputxml><inputxml>'.
        '</inputxml></inputxml>'.'<starttime>'.$start_date.'</starttime>'.
            '<endtime>'.$end_date.'</endtime>'.
            '<akb020>'.$hospital_org_id.'</akb020></input>';
        //出参
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);

        $fileContent = '入参'.$xml.'+出参'.json_encode($result_list);
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS024/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);

        //$response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($result_list);
        //dump($response);
        echo $response;die();
    }

	
/**
     * 查询医院微信订单信息
     * @param 
     */
    function weixin(){
		$akb020 = $_POST['hospital_org_id'];//医院机构编码
        $hisordnum = $_POST['hospital_order_no'];//医院订单号
        $psordnum = $_POST['ssp_order_no'];//平台订单号
        $paymode = $_POST['channel_id'];
        $appid = $_POST['app_id'];
        $funNo='HIS021';    //交易编号
        $xml="<input><Request><akb020>".$akb020."</akb020><functionid>HIS021</functionid>
<hisordnum>".$hisordnum."</hisordnum>
<psordnum>".$psordnum."</psordnum>
<paymode>".$paymode."</paymode>
</Request>
</input>";
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);

        $fileContent = '入参'.$xml.'+出参'.json_encode($result_list);
        $dir = "soapGetDate/" . date("Y-m-d") . "/HIS021/";
        $filename = date("H_i_s") . "_" . rand(10000, 99999);
        writeLog($dir, $filename, $fileContent);

		if($result_list['resultcode'] == "-1" && $result_list['resultmessage'] == "获取数据失败"){
			$res = [
				"resultcode" => "1",
				"resultmessage" => "该订单信息医院不存在",
				"item" => [
					"hisordnum" => "",
					"totalamt" => "",
					"coordinationpay" => "",
					"scardamt" => "",
					"cashpay" => "",
					"payflag" => "3"
				]
			];
			$response = json_encode($res);
		}else{
			$response = json_encode($result_list);
		}
        //dump($response);
        echo $response;die();
    }

}
?>